package com.zhao;

import java.util.Arrays;

/**
 * @program: arithmetic-do-exercise
 * @author: zhaohuan
 * @create: 2022-09-28 10:38
 * @description
 **/
public class Test {

    public static void main(String[] args) {

        int num1[] = new int[4];
        num1[0] = 1;
        num1[1] = 6;
        int num2[] = new int[4];
        num2[0] = 2;
        num2[1] = 5;
        fun(num1, 2, num2, 2);
        System.out.println(Arrays.toString(num1));

    }


    public static int[] fun(int num1[], int m, int num2[], int n) {
        int step = m + n - 1; m --; n --;
        while(step > -1) {
            if (m < 0) {
                num1[step] = num2[n --];
            } else if (n < 0) {
                num1[step] = num1[m --];
            }else if (num1[m] > num2[n]) {
                num1[step] = num1[m--];
            } else {
                num1[step] = num2[n --];

            }
            step --;
        }
        return num1;
    }


}

